<template>
    <div class="container">
        <h3>订单管理</h3>
        <el-row style="margin-top:20px;">
            <el-col :span="7">
                <el-input placeholder="订单号/客户" v-model="searchName" style="width:300px;">
                    <i slot="prefix" class="el-input__icon el-icon-search"></i>
                    <el-button slot="append" @click="handleSearch">搜索</el-button>
                </el-input>
            </el-col>

         <el-button
             v-if="!added"
             type="primary"
             @click="handleadd"
             style="float:right; margin-right: 10px"
         >新增订单</el-button>
        </el-row>

        <el-table
            :data="tableData"
            border
            style="margin-top:20px;"
            ref="multipleTable"
            header-cell-class-name="table-header"
        >
            <el-table-column prop="orderNo" sortable label="订单号"></el-table-column>
            <el-table-column prop="clientName" sortable label="客户"></el-table-column>
			<el-table-column prop="source" sortable label="订单来源"></el-table-column>
            <el-table-column prop="createtime" sortable label="下单时间"></el-table-column>
            <el-table-column label="操作" width="150" align="center">
                <template slot-scope="scope">
                    <el-button
                        v-if="!check"
                        type="text"
                        @click="handleCheck(scope.$index, scope.row)"
                    >查看</el-button>
					<el-button type="text" >
						<el-dropdown style="color: #409EFF; font-size:12px">
							<span class="el-dropdown-link">
								更多
							</span>
							<el-dropdown-menu slot="dropdown">
								<el-dropdown-item>
									<el-button
                                        v-if="!edit"
										type="text"
										@click="handleEdit(scope.$index, scope.row)"
										style="color: #666"
									>编辑</el-button>
								</el-dropdown-item>
								<el-dropdown-item>
									<el-button
                                        v-if="!del"
									    type="text"
										style="color: red;"
									    @click="handleDelete(scope.$index, scope.row)"
									>删除</el-button>
								</el-dropdown-item>
							</el-dropdown-menu>
						</el-dropdown>
					</el-button>
					
                </template>
            </el-table-column>
        </el-table>
        <el-pagination
            layout="total, prev, pager, next, jumper"
            :page-size="pagesize"
            :current-page.sync="currentPage"
            :total="total"
            @current-change="handleCurrentChange"
            style="margin-top:20px"
        ></el-pagination>
    </div>
</template>
<script>
import { order_findByList,order_delete } from '@/request/breedApi';
export default {
    data() {
        return {
			labelPosition:'right',
			ruleForm:{},
            total: 0,
            currentPage: 1,
            pagesize: 10,
            searchName: '',
            tableData: [],
            form: {},
            added:true,
            check:true,
            edit:true,
            del:true,
        };
    },
    mounted() {
        this.init();
        this.judgmentAuthority()
    },
    methods: {
		handleDelete(index,row){
			order_delete(row.id).then((res)=>{
				this.$notify({
					title: '提示',
					message: '删除成功',
					type: 'success',
					duration:1000
				});
				this.init()
			})
		},
		// 跳转到编辑
		handleEdit(index,row){
			this.$router.push({
				path:'/yzorder/edit',
				query:{id:row.id,orderNo: row.orderNo}
			})
		},
		// 跳转到新增
		handleadd(){
			this.$router.push({
				path:'/yzorder/added'
			})
		},
		
		// 分页
        handleCurrentChange(val) {
            this.currentPage = val;
            this.init();
        },
		// 页面一进来加载
        init() {
            // var params = {
            //     "searchName": this.searchName,
            //     "page": this.currentPage
            // }
            let params = {
                pageno: this.currentPage,
                state: this.state,
                pagesize: 10,
                starttime: this.start,
                endtime: this.end
            };
            order_findByList(params).then((res) => {
                console.log(res,'1111111')
                if (res.code == 200) {
                    const list = []
                    res.data.map((item) => {
                        // const lists = {}
                        // lists.orderNumber = item.clientOrder.orderNo
                        // lists.customer = item.clientOrder.clientName
                        // lists.source = item.clientOrder.source
                        // lists.time = item.clientOrder.createtime
                        // lists.id = item.clientOrder.id
                        // lists.orderNo = item.clientOrder.orderNo
                        list.push(item.clientOrder)
                    })
                    console.log(list,'111111')
                    this.tableData = list;
                    this.total = res.data.length;
                }
            });
        },
		// 查看
        handleCheck(index, row) {
            this.$router.push({
            	path:'/yzorder/check',
				query:{id:row.id}
            })
        },
        //搜索
        handleSearch() {
            this.currentPage = 1;
            this.init();
        },

        //判定操作按钮显示
        judgmentAuthority(){
            var type = JSON.parse(localStorage.getItem("panduanzhuangtai"))
                type.map(item1 => {
                    if(item1.name == '订单管理' && item1.children != null){
                        for(var i = 0; i < item1.children.length; i++){
                            if(item1.children[i].name == '新增') this.added = false;
                            if(item1.children[i].name == '查看') this.check = false;
                            if(item1.children[i].name == '编辑') this.edit = false;
                            if(item1.children[i].name == '删除') this.del = false;
                        }
                    }
                })
        }
 
    }
};
</script>

<style scoped lang="less">
/deep/.upload-daoru {
    background: #eee;
    .el-upload {
        border: none;
        width: auto;
        height: auto;
        border-radius: 0;
        float: right;
        margin-right: 10px;
    }
}
.el-table {
    margin-top: 20px;
}
.el-pagination {
    text-align: center;
}
.el-pagination {
    text-align: center;
}
.el-col {
    margin-bottom: 0;
}
.avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    width:180px;
    overflow: hidden;
  }
  
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .el-upload--text{
      width:180px;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>